<?php
    class UploadFileAction extends CAction {
        public function run() {
            // Define a destination
			//$targetFolder = '/greatnutrition/upload/'; // Relative to the root
            $targetFolder = Yii::app()->baseUrl.'/upload/';
			if (!empty($_FILES)) {
				$tempFile = $_FILES['Filedata']['tmp_name'];
				$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
				$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
				// Validate the file type
				$fileTypes = array('xls','csv'); // File extensions
				$fileParts = pathinfo($_FILES['Filedata']['name']);
				
				if (in_array($fileParts['extension'],$fileTypes)) {
					move_uploaded_file($tempFile,$targetFile);
					echo '1';
				} else {
					echo 'Invalid file type.';
				}
			}
        }
    }
